package me.youline.dataServer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.junit.Assert;


public class CollectionAssertUtils {

	public static<T> void assertCommonSort(Collection<T> expected, Collection<T> actual){
		assertNotNull(expected);
		assertNotNull(actual);
		assertSizeEql(expected, actual);
		List<T> expecteds = new ArrayList<T>(expected);
		List<T> actuals = new ArrayList<T>(actual);
		for(int i = 0 ; i < expected.size(); i++){
			Assert.assertEquals(expecteds.get(i),actuals.get(i));
		}
	}
	 
	
	public static<T extends Comparable<? super T>> void assertCommonsVal(Collection<T> expected, Collection<T> actual){
		assertCommonsVal("the value in collection not eq", expected, actual);
	}
	
	public static<T extends Comparable<? super T>> void assertCommonsVal(String message, Collection<T> expected, Collection<T> actual){
		List<T> expecteds = getList(expected);
		List<T> actuals = getList(actual);
		assertSizeEql(expecteds, actuals);
		Collections.sort(expecteds);
		Collections.sort(actuals);
		Assert.assertEquals(message,expecteds ,actuals);
	}
	
	public static<T> void assertSizeEql(Collection<T> expected, Collection<T> actual){
		Assert.assertEquals(expected.size(), actual.size());
	}
	
	public static<T> void assertNotNull(Collection<T> e){
		Assert.assertNotNull(e);
	}
	
	private static<T> List<T> getList(Collection<T> collection){
		return new ArrayList<T>(collection);
	}
	
	
	
}
